package com.tongji.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tongji.service.ChaxunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("pandian")
public class ChaxunController {

    @Autowired
    ChaxunService chaxunService;

    //到达盘点查询页面
    @RequestMapping("toChaXun.do")
    public String toChaXun() {
        return "pandian/pandianjiluchaxun";
    }

    //查询盘点记录
    @RequestMapping("getlog.do")
    public String getlog(String custID, String date1, String date2, String pageSize, String pageNum, HttpServletRequest request) {
        System.out.println("进入请求");
        System.out.println(custID + "-" + date1 + "-" + date2);

        //数据放域 回显页面
        request.getSession().setAttribute("custID", custID);
        request.getSession().setAttribute("date1", date1);
        request.getSession().setAttribute("date2", date2);


        //开始分页
        if (pageSize.equals("")) {
            PageHelper.startPage(1, 5);
            //pageSize & pageNum 放域
            request.getSession().setAttribute("num1", 1);
            request.getSession().setAttribute("size1", 5);
        } else {
            PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
            //pageSize & pageNum 放域
            request.getSession().setAttribute("num1", Integer.parseInt(pageNum));
            request.getSession().setAttribute("size1", Integer.parseInt(pageSize));
        }

        //查询数据
        List<Map<String, Object>> list = chaxunService.getlog(custID, date1, date2);
        System.out.println("list为：");
        System.out.println(list);

        PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(list);
        request.getSession().setAttribute("pageInfochaxun", pageInfo);

        return "pandian/pandianjiluchaxun";
    }
}
